#include<stdio.h>

int num, answer;
char flag[20][20] = {0};
int movex[] = {-1, 1, 0, 0};
int movey[] = {0, 0, -1, 1};

void search(int step)
{
      int i, j, k, x, y, valid;
      if(answer < step) answer = step;
      for(i = 0; i < num; i++)
      {
            for(j = 0; j < num; j++)
            {
                  x = i;
                  y = j;
                  valid = 1;
                  if ( flag[i][j] == 'a' || flag[i][j] == 'X') valid = 0;
                 
                  
                  for(k = 0;k < 4; k++)
                  {
                        x = i;
                        y = j;
                        while(x >= 0 && x < num && y >= 0 && y < num )
                        {
                            x += movex[k];
                            y += movey[k];
                            if(flag[x][y] == 'X') break;
                            if(flag[x][y] == 'a') valid = 0;
                        }
                  }
                  
                  if(valid == 1)
                  {
                      flag[i][j] = 'a';
                      search(step + 1);
                      flag[i][j] = '.';
                  }
            }
      }
      
      
}
int main()
{
    int i;
    while (1)
    {
        scanf("%d", &num);
        if (num == 0) break;
        for (i = 0; i < num; ++ i)
            scanf("%s", flag[i]);
        answer = 0;
        search(0);
        printf("%d\n",answer);
    }
    return 0;
}
